package com.pangu.ui.browser;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;

import com.pangu.AMApplication;
import com.pangu.ui.view.PinnedExpandableListView;

/**
 * 可以头部固定的GroupItemBroswer 不可展开和收缩
 * 
 * @author cxlin
 * 
 * @date 2014-11-10 上午11:11:27
 */
public abstract class PinnedGroupItemBroswer<A extends AMApplication> extends GroupItemBroswer<A> implements
		OnGroupClickListener {

	public PinnedGroupItemBroswer(Context context) {
		super(context);
	}

	public PinnedGroupItemBroswer(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		((PinnedExpandableListView) adapterView).refreshPinnedHead();
	}

	@Override
	protected AdapterView createAdapterView() {
		PinnedExpandableListView eListView = new PinnedExpandableListView(getContext());

		setListViewParameter(eListView);
		// 添加头部
		addListHeader(eListView);
		addListFooter(eListView);

		return eListView;
	}

	@Override
	protected void setListViewParameter(ExpandableListView eListView) {
		super.setListViewParameter(eListView);

		eListView.setVerticalFadingEdgeEnabled(true);
		eListView.setDividerHeight(0);
		eListView.setDivider(null);
		// 取消分组列表展开收缩
		eListView.setOnGroupClickListener(this);
	}

	@Override
	public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
		return true;
	}
}
